//建造者模式
#include<iostream>
#include<memory>
#include<string>
using namespace std;

class Computer{
    public:
    using ptr=shared_ptr<Computer>;
    void setBorad(const string& borad){
        _board=borad;
    }
    void setDisplay(const string& display){
        _display=display;
    }
    virtual void setOs()=0;
    string toString(){
        string ret;
        ret="Computer:{\n";
        ret+="\tboard: "+_board+",\n";
        ret+="\tdisplay: "+_display+",\n";
        ret+="\tos: "+_display+"\n";
        ret+="}\n";
        return ret;
    }
    protected:
    string _board;
    string _display;
    string _os;
};
class MacbookComputer:public Computer{
    public:
    void setOs() override{
        _os="Mac Os X12";
    }
};
class Builder{
    public:
    using ptr=shared_ptr<Builder>;
    virtual void buildBoard(const string&)=0;
    virtual void buildDisplay(const string&)=0;
    virtual void buildOs()=0;
    virtual Computer::ptr getcomputer()=0;
};
class MacbookBuilder:public Builder{
    public:
    MacbookBuilder():_computer(new MacbookComputer()){}
    void buildBoard(const string& board) override{
        _computer->setBorad(board);
    }
    void buildDisplay(const string& display) override{
        _computer->setDisplay(display);
    }
    void buildOs() override{
        _computer->setOs();
    }
    Computer::ptr getcomputer() override{
        return _computer;
    }
    private:
    Computer::ptr _computer;
};
class Director{
    public:
    Director(Builder* builder):_builder(builder){}
    void construct(const string& board,const string& display){
        _builder->buildBoard(board);
        _builder->buildDisplay(display);
        _builder->buildOs();
    }
    private:
    Builder::ptr _builder;
};

int main()
{
    Builder* builder=new MacbookBuilder();
    unique_ptr<Director> director(new Director(builder));
    director->construct("英特尔主板","VOC显示器");
    shared_ptr<Computer> computer=builder->getcomputer();
    cout<<computer->toString();
    return 0;
}